package ink.xiaobaibai.common;

/**
 * @description: 角色事件
 * @author: 小白白
 * @create: 2021-06-10
 **/

public class RoleEvents<T> {

    private String role;
    private EventsReturnInterface<T> distributorEvent;
    private EventsReturnInterface<T> agentEvent;
    private EventsReturnInterface<T> operatorEvent;
    private EventsReturnInterface<T> adminEvent;
    private EventsReturnInterface<T> operaAdmin;
    private EventsVoidInterface distributorEventVoid;
    private EventsVoidInterface agentEventVoid;
    private EventsVoidInterface operatorEventVoid;
    private EventsVoidInterface adminEventVoid;
    private EventsVoidInterface operaAdminVoid;

    public RoleEvents(String role) {
        this.role = role;
    }

    public RoleEvents<T> distributor(EventsReturnInterface<T> event) {
        this.distributorEvent = event;
        return this;
    }

    public RoleEvents<T> agent(EventsReturnInterface<T> event) {
        this.agentEvent = event;
        return this;
    }

    public RoleEvents<T> oa(EventsReturnInterface<T> event) {
        this.operaAdmin = event;
        return this;
    }

    public RoleEvents<T> operator(EventsReturnInterface<T> event) {
        this.operatorEvent = event;
        return this;
    }

    public RoleEvents<T> admin(EventsReturnInterface<T> event) {
        this.adminEvent = event;
        return this;
    }


    public RoleEvents distributor(EventsVoidInterface event) {
        this.distributorEventVoid = event;
        return this;
    }

    public RoleEvents agent(EventsVoidInterface event) {
        this.agentEventVoid = event;
        return this;
    }

    public RoleEvents oa(EventsVoidInterface event) {
        this.operaAdminVoid = event;
        return this;
    }

    public RoleEvents operator(EventsVoidInterface event) {
        this.operatorEventVoid = event;
        return this;
    }

    public RoleEvents admin(EventsVoidInterface event) {
        this.adminEventVoid = event;
        return this;
    }

    public T execute() {
        switch (this.role) {
            case MyRole.DISTRIBUTOR:
                if (this.distributorEvent != null) {
                    return this.distributorEvent.event();
                } else {
                    this.distributorEventVoid.event();
                    return null;
                }
            case MyRole.AGENT:
                if (this.agentEvent != null) {
                    return this.agentEvent.event();
                } else {
                    this.agentEventVoid.event();
                    return null;
                }
            case MyRole.OPERATOR:
                if (this.operatorEvent != null || this.operaAdmin != null) {
                    if (this.operatorEvent != null) {
                        return this.operatorEvent.event();
                    } else {
                        return this.operaAdmin.event();
                    }
                } else {
                    if (this.operatorEventVoid != null) {
                        this.operatorEventVoid.event();
                    } else {
                        this.operaAdminVoid.event();
                    }
                    return null;
                }
            case MyRole.ADMIN:
                if (this.adminEvent != null || this.operaAdmin != null) {
                    if (this.adminEvent != null) {
                        return this.adminEvent.event();
                    } else {
                        return this.operaAdmin.event();
                    }
                } else {
                    if (this.adminEventVoid != null) {
                        this.adminEventVoid.event();
                    } else {
                        if (this.operaAdminVoid != null) {
                            this.operaAdminVoid.event();
                        }
                    }
                    return null;
                }
            default:
                return null;
        }
    }

}
